package com.heima.article.feign;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import com.heima.article.service.ApArticleConfigService;
import com.heima.article.service.ApArticleService;
import com.heima.feign.article.IArticleClient;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.article.pojos.ApArticleConfig;
import com.heima.model.article.dtos.CollectionBehaviorDto;
import com.heima.model.behavior.dtos.LikeBehaviorDto;
import com.heima.model.behavior.dtos.ReadBehaviorDto;
import com.heima.model.comment.dto.CommentConfigDto;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.GraphicDataParametersDto;
import com.heima.model.wemedia.dtos.WmCommentDto;
import com.heima.model.wemedia.pojos.NewPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author jack
 * @data 2024 15:19
 */
@RestController
public class ArticleClient implements IArticleClient {
    @Autowired
    private ApArticleService apArticleService;
    @Autowired
    private ApArticleConfigService apArticleConfigService;


    /**
     * 新增或修改app文章信息
     *
     * @param articleDto
     * @return
     */
    @PostMapping("/api/v1/article/saveOrUpdate")
    public ResponseResult saveArticle(@RequestBody ArticleDto articleDto) {
        return apArticleService.saveOrUpdateArticle(articleDto);
    }

    @Override
    @PostMapping("/api/v1/article/getComments")
    public PageResponseResult getComments(WmCommentDto wmCommentDto) {
        return apArticleService.getComments(wmCommentDto);
    }

    @Override
    @PostMapping("/api/v1/article/addLike")
    public ResponseResult addLike(@RequestBody LikeBehaviorDto likeBehaviorDto) {
        return apArticleService.addLike(likeBehaviorDto);
    }

    /**
     * 通过文章ID查找文章配置
     *
     * @param articleId 文章ID
     * @return {@link ResponseResult}<{@link ?}>
     */
    @Override
    public ResponseResult<?> findArticleConfigByArticleId(Long articleId) {
        ApArticleConfig apArticleConfig = apArticleConfigService.getOne(Wrappers.<ApArticleConfig>lambdaQuery().eq(ApArticleConfig::getArticleId, articleId));
        return ResponseResult.okResult(apArticleConfig);
    }

    /**
     * 读取行为
     *
     * @param readBehaviorDto 读取行为dto
     * @return {@link ResponseResult}
     */
    @Override
    @PostMapping("/api/v1/article/readBehavior")
    public ResponseResult readBehavior(@RequestBody ReadBehaviorDto readBehaviorDto) {
        return apArticleService.readBehavior(readBehaviorDto);
    }

    /**
     * 添加收藏的行为
     *
     * @param collectionBehaviorDto 集合行为dto
     * @return {@link ResponseResult}
     */
    @PostMapping("/api/v1/article/addCollection")
    public ResponseResult addCollection(CollectionBehaviorDto collectionBehaviorDto) {
        return apArticleService.addCollection(collectionBehaviorDto);
    }

    @Override
    public ResponseResult addComment(Long articleId) {
        return apArticleService.addComment(articleId);
    }

    @PostMapping("/api/v1/article/graphicAndTextualData")
    public ResponseResult graphicAndTextualData(@RequestBody GraphicDataParametersDto graphicDataParametersDto) {
        return apArticleService.graphicAndTextualData(graphicDataParametersDto);
    }

    @Override
    @PostMapping("/api/v1/article/updateCommentStatus")
    public ResponseResult updateCommentStatus(@RequestBody CommentConfigDto wmUpdateStatusDto) {
        return apArticleConfigService.updateCommentStatus(wmUpdateStatusDto);
    }

    /**
     * 查询所有的图文列表数据
     *
     * @param newPageDto 新页面dto
     */
    @PostMapping("/api/v1/article/newPage")
    public PageResponseResult newPage(@RequestBody NewPage newPageDto) {
        return apArticleService.newPage(newPageDto);
    }

    @GetMapping("/api/v1/article/deletingCommentsReducesComments/{entryId}/{count}")
     public void deletingCommentsReducesComments(@PathVariable("entryId") Long entryId, @PathVariable("count") Long count){
        apArticleService.deletingCommentsReducesComments(entryId, count);
    }
}
